function propensities=propen_matt(demographics)
    
    %2011.9.13: In part of ecological inference, this m-file run probit
    %regression, and compute predicted probability of choosing 1.
    %We compute propensity scores for each state, and also for nation-wide pooled data.
    
    % Input: demographic variables (for each column): stateicp, year (0=1980, 1=2000), log income, education, age, white, unemployed.
    % Output: "SampleSize x 2". First column: propensity scores onditioned on stateicp. Second Column: propensity scores unconditioned.
    
    SampleSize=length(demographics);
    propensities=zeros(SampleSize,2);
    
    %% Propensity Scores conditioned on stateicp.
    
    % In 2 x NumofStates matrix, store stateicp, and the last sample index of each state.
    [tmp1, tmp2,tmp3]=unique(demographics(:,1),'last');
    states=[tmp1,tmp2];
    
    max_ind=0;
    for st=1:length(states)
        
        min_ind=max_ind+1;
        max_ind=states(st,2);

        % By stateicp: 
        tmp_demographics=demographics(min_ind:max_ind,:);

        % Probit regressions and predict probability.
        beta_hat=glmfit(tmp_demographics(:,3:end),tmp_demographics(:,2),'binomial','link','probit');
        propensities(min_ind:max_ind,1)=glmval(beta_hat, tmp_demographics(:,3:end),'probit');

    end
    
    
    %% Propensity Scores unconditioned.
    
    % Probit regressions and predict probability.
    beta_hat=glmfit(demographics(:,3:end),demographics(:,2),'binomial','link','probit');
    propensities(:,2)=glmval(beta_hat, demographics(:,3:end),'probit');


end

